package Dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginDao {
    public boolean queryBookById(String account, String password) throws Exception {
        Connection conn = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/library";
            String username = "root";
            String password1 = "17876724541";
            conn = DriverManager.getConnection(url, username, password1);

            String sql = "select userId from user where account=? and password=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, account);
            ps.setString(2, password);
            rs = ps.executeQuery();

            return rs.next(); // Return whether a matching user is found or not

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            // Close resources in the finally block
            if (rs != null) {
                rs.close();
            }
            if (conn != null) {
                conn.close();
            }
        }

        return false; // Return false if an exception occurs
    }
}
